package graphics;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import playlist.Crawler;

import state.State;

public class Background {
	
	private Image mainImage = null;
	private Image activeImage = null;
	private Image activeBlurryImage = null;
	private Image passiveImage = null;
	private Image passiveBlurryImage = null;
	
	public Background() throws Throwable {
		activeImage = Image.createImage("/Active.gif");
		activeBlurryImage = Image.createImage("/ActiveBlurry.gif");
		passiveImage = Image.createImage("/Passive.gif");
		passiveBlurryImage = Image.createImage("/PassiveBlurry.gif");
	}
	
	public void repaint(Graphics graphics) {
		boolean isBlurry = (Crawler.state().equals(State.MODE_CHOICE))
			|| (Crawler.state().equals(State.SEARCH_CHOICE));
		
		
		if (Crawler.state().equals(State.PLAY_MP3)) {
			if (isBlurry) {
				mainImage = activeBlurryImage;
			} else {
				mainImage = activeImage;
			}			
		} else {
			if (isBlurry) {
					mainImage = passiveBlurryImage;
				} else {
					mainImage = passiveImage;
				}			
		}
		
		if (Crawler.state().equals(State.SEARCH_CHOICE)) {
			graphics.drawImage(activeBlurryImage, 0, 0, Graphics.LEFT | Graphics.TOP);
		}
		
		graphics.drawImage(mainImage, 0, 0, Graphics.LEFT | Graphics.TOP);
	}
}
